<%--                                                                       --%>
<%-- Copyright (c) 2003-2004 BroadVision, Inc.  All rights reserved.       --%>
<%--                                                                       --%>
<%-- This software is copyrighted. Under the copyright laws, this software --%>
<%-- may not be copied, in whole or in part, without prior written consent --%>
<%-- of BroadVision, Inc. or its assignees. This software is provided      --%>
<%-- under the terms of a license between BroadVision and the recipient,   --%>
<%-- and its use is subject to the terms of that license.                  --%>
<%--                                                                       --%>
<%-- This software may be protected by one or more U.S. and International  --%>
<%-- patents.  Certain applications of BroadVision One-To-One software are --%>
<%-- covered by U.S. patent 5,710,887.                                     --%>
<%--                                                                       --%>
<%-- TRADEMARKS: BroadVision and BroadVision One-To-One are registered     --%>
<%-- trademarks of BroadVision, Inc., in the United States and the         --%>
<%-- European Community, and are trademarks of BroadVision, Inc., in other --%>
<%-- countries.  The BroadVision logo, is a trademark of BroadVision,      --%>
<%-- Inc., in the United States and other countries.                       --%>


<%@ page language="java" %>
<%@ page import = "org.apache.struts.util.RequestUtils" %>
<%@ page import = "org.apache.commons.beanutils.DynaBean" %>
<%@ page import = "org.apache.commons.beanutils.PropertyUtils" %>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> 
<%@ taglib uri="/WEB-INF/bv-html.tld" prefix="bvhtml" %>


<script language="JavaScript">
<!--

<%--
  String relativeDir = "/" + csMessageListEditForm.getServiceName() 
                           + "/microsite/"
                           + csMessageListEditForm.getMicrositeId()
                           + "/bv_dgattachments/" 
                           + csMessageListEditForm.getDiscussionId();

  String nextAction = "/cs/msgPageAttachmentAdd.do";
  String nextPage = RequestUtils.computeURL(pageContext,
                                           null,
                                           null,
                                           nextAction,
                                           null,
                                           null,
                                           false);

--%>

function openwin(file) {
  window.open(escape(file), "NewWindow", 'toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,copyhistory=yes,width=450,height=338');
}

function onFileInputFocus()
{
  return document.csMessageListEditForm.newFile.focus();
}

function onClickReset() {
  document.csMessageListEditForm.reset();
}

function onClickCancel(theForm) {
  <logic:equal name="csMessageListEditForm" property="numFiles" value="0">
  document.csMessageListEditForm.action = '<html:rewrite page="/cs/messageView.do"/>';
  </logic:equal>
  <logic:notEqual name="csMessageListEditForm" property="numFiles" value="0">
  document.csMessageListEditForm.action = '<html:rewrite page="/cs/messageCancel.do"/>';
  </logic:notEqual>
  document.csMessageListEditForm.encoding = "application/x-www-form-urlencoded";
  document.csMessageListEditForm.submit();
}

<%--
// Load the related items chosen in the pop-up window
function loadRelatedItems(OIDs, contentType) {
  document.csMessageListEditForm.relatedItems.value = OIDs;
  document.csMessageListEditForm.relatedItemsContentType.value = contentType;
  document.csMessageListEditForm.action = '<html:rewrite page="/cs/messageAddRelated.do"/>'
  document.csMessageListEditForm.encoding = "application/x-www-form-urlencoded";
  document.csMessageListEditForm.method = "post";
  document.csMessageListEditForm.submit();
}
--%>

function onClickPost() {
  if (validateForm()) {
    //document.csMessageListEditForm.action = '<html:rewrite page="/cs/messageAttachmentsSave.do"/>';
    //document.csMessageListEditForm.encoding = "application/x-www-form-urlencoded";
    document.csMessageListEditForm.action = '<html:rewrite page="/cs/messageSave.do"/>';
    document.csMessageListEditForm.submit();
  }
}

function confirmDeleteMessage()
{
   if (confirm('<bean:message key="cs.confirm.delete.message"/>'))
   {
      return true;
   }
   else
   {
      return false;
   }
}

//
// Trims leading blanks.
//
function stringLeftTrim(s)
{
   return s.replace(/^ +/, "");
}

//
// Trims trailing blanks.
//
function stringRightTrim(s)
{
   return s.replace(/ +$/, "");
}

//
// Trims leading and trailing blanks.
//
function stringTrim(s)
{
   return stringRightTrim(stringLeftTrim(s));
}

<%--
function removeRelatedItem(OID, contentType) {
  document.csMessageListEditForm.action = '<html:rewrite page="/cs/messageRelatedItemRemove.do"/>';
  document.csMessageListEditForm.removeRelatedId.value = OID;
  document.csMessageListEditForm.removeRelatedContentType.value = contentType;
  document.csMessageListEditForm.parentContentType.value = '25'; // Message
  document.csMessageListEditForm.encoding = "application/x-www-form-urlencoded";
  document.csMessageListEditForm.method = "post";
  document.csMessageListEditForm.submit();
}


function onClickBrowseRelatable() {
  if(document.csMessageListEditForm.selectedRelatableType.value < 0) return;
  var redirectUrl;
  switch(document.csMessageListEditForm.selectedRelatableType.value) {
  // Messages
  case "25":
    redirectUrl = '<html:rewrite page="/cs/relatedMessage.do" name="csMessageListEditForm" property="urlParams" paramId="contentName" paramName="csMessageListEditForm" paramProperty="discussionName"/>';
    break;
  // documents
  case "322":
    redirectUrl = '<html:rewrite page="/cs/relatedDocument.do" name="csMessageListEditForm" property="urlParams" paramId="contentName" paramName="csMessageListEditForm" paramProperty="discussionName"/>';
    break;
  default:
    redirectUrl = '<html:rewrite page="/cs/categoryBrowse.do" name="csMessageListEditForm" property="urlParams" paramId="contentName" paramName="csMessageListEditForm" paramProperty="discussionName" />';
    if(redirectUrl.indexOf("?") > 0) {
      redirectUrl += '&amp;contentTypeId=' + document.csMessageListEditForm.selectedRelatableType.value;
    }
    else {
      redirectUrl += '?contentTypeId=' + document.csMessageListEditForm.selectedRelatableType.value;
    }

  }
  // The following two lines are necessary for netscape to correctly send the
  // query string
  var re = new RegExp('&amp;','gi');
  var newRedirectUrl = redirectUrl.replace(re,"&");

  var win = window.open(newRedirectUrl,'addRelatedItem', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=yes,width=700,height=500');
  win.focus();
}
--%>

//
// Validate the user's entries.
//
function validateForm() 
{
   var email = stringTrim(document.csMessageListEditForm.email.value);

   if (email == "") 
   {
      alert('<bean:message key="cs.error.message.email"/>');
      return false;
   }

   var title = stringTrim(document.csMessageListEditForm.title.value);

   if (title == "") 
   {
      alert('<bean:message key="cs.error.message.title"/>');
      return false;
   }


   var attachName = stringTrim(document.csMessageListEditForm.attName.value);
   var attachFile = stringTrim(document.csMessageListEditForm.attOriginalFileName.value);

   if (attachName != "" || attachFile != "")
   {
      alert('<bean:message key="cs.error.attachment.add.more"/>');
      return false;
   }
   
   document.csMessageListEditForm.email.value = email;
   document.csMessageListEditForm.title.value = title;
 

   return true;
}

// -->
</script>

<!-- Zone 5 starts here.  -->
      
<table class="zoneFive" width="100%" border="0" cellspacing="0" cellpadding="0" 
       summary="content area">
  <tr>
    <td valign="top">
    
    <!--start microsite logo and name here-->
      <div class="pageTitle">
        <%@ include file="/cs/microsite/micrositeNaviInfo.jsp" %>
      </div> 
    <!--end microsite logo and name here-->
    
    <!--start title bar here-->
    <div class="pageSubtitle">
      <span class="left">
        <bean:write name="discussionGroupDTO" property="name" />&nbsp;<bean:message key="cs.discussion"/>
      </span>
      <span class="right">
        <!-- Admin can always create and delete discussion message.            -->
        <!-- Participant can create discussion message if the microsite        -->
        <!-- is not closed. Therefore, we only check isReadOnly for the        -->
        <!-- "Reply Message" button.                                          -->
        <logic:notEqual name="isMSReadOnly" scope="request" value="true">
          <input type="button" value="<bean:message key="cs.message.reply"/>" onclick="location='#reply'" class="titleButton"/>
        </logic:notEqual>
        <logic:equal name="isMSOwner" scope="request" value="true">
          <input type="button" onclick="if(confirmDeleteMessage()) location='<html:rewrite page="/cs/messageDelete.do" name="discussionMessageDTO" property="urlParams"/>';" class="titleButton" value="<bean:message key="cs.message.delete"/>"/>
        </logic:equal>
      </span>
    </div>  
    
    <div class="blockWrap">
    
    <div class="globalButtonWrap">
      <logic:present name="discussionMessageDTO" property="previousUrlParams" scope="request">
        <input type="button" name="btn1" class="globalButton" value="<bean:message key="cs.message.previous"/>" onclick="location='<html:rewrite page="/cs/messageView.do?displayMsg=true" name="discussionMessageDTO" property="previousUrlParams" scope="request"/>';"/>
      </logic:present>     
      <logic:present name="discussionMessageDTO" property="nextUrlParams" scope="request">
        <input type="button" name="bnt2" class="globalButton" value="<bean:message key="cs.message.next"/>" onclick="location='<html:rewrite page="/cs/messageView.do?displayMsg=true" name="discussionMessageDTO" property="nextUrlParams" scope="request"/>';"/>
      </logic:present>  
      <input type="button" name="bnt3" class="globalButton" value="<bean:message key="cs.message.list"/>" onclick="location='<html:rewrite page="/cs/discussionView.do?displayMsg=true" name="micrositeNaviInfoView" property="urlParams"/>'">
      <input type="button" name="bnt4" class="globalButton" value="<bean:message key="cs.discussions.index"/>" onclick="location='<html:rewrite page="/cs/discussionList.do" name="micrositeNaviInfoView" property="urlParams"/>'">
    </div>
      
<!--end title bar here-->

<!--start main content area here-->

<!--start reply message table here-->
<!--start title bar here-->
<div class="pageSubsubtitle">
  <span class="left">
    <bean:write name="discussionMessageDTO" property="title"/>
  </span>
  <span class="right">
<bean:write name="discussionMessageDTO" property="lastModTime" formatKey="format.datetime.full"/>
  </span>
</div>  
      
<table class="labelForm" width="100%" border="0" cellspacing="0" 
     cellpadding="0" summary="message content table">
     
  <tr>
    <td width=15% class="label"><bean:message key="cs.message.author"/>:</td>
    <td width=85% class="labelField">
      <bean:write name="discussionMessageDTO" property="author"/>
       &nbsp;&nbsp;&nbsp;
       <a href="mailto:<bean:write name="discussionMessageDTO" property="email"/>">
       <bean:write name="discussionMessageDTO" property="email"/></a>
    </td>
  </tr>
  <tr>
    <td width=15% class="label">
	<bean:message key="cs.message"/>:
    </td>
    <td width=85% class="labelField">
<%
    String bodyText = "";
    try {
      com.broadvision.web.util.ViewDynaBean bean = (com.broadvision.web.util.ViewDynaBean) request.getAttribute("discussionMessageDTO");
      bodyText = (String)PropertyUtils.getProperty(bean, "body");
    }
    catch (Exception ee) {
    }
%>
    <%= com.broadvision.xml.util.XmlUtils.convertToHtmlLineBreaks(bodyText) %>
    </td>
  </tr>
  
  <tr>
    <td colspan="2" valign="top" class="label">
    <!--Start Attachments Content Detail Area Here-->
	  <!-- Attachment list begins. -->
    <bean:define id="beanUsed" name="discussionMessageDTO" toScope="request" />
      <%@ include file="/cs/microsite/attachment/attachmentView.jsp" %>
      <!-- Attachment list ends. -->
    </td>
  </tr>
  <logic:present name="discussionMessageDTO" property="parentUrlParams">
  <tr>
    <td colspan="2" class="label"><bean:message key="cs.message.posted.parent"/>:
    <img src="<%= request.getContextPath() %>/cs/images/buttons/global/gbtn_message.gif" width="22" height="18" altKey="cs.message" border="0" align="top">
      <html:link page="/cs/messageView.do?displayMsg=true" name="discussionMessageDTO" 
                 property="parentUrlParams">
                 <b><bean:write name="discussionMessageDTO" property="parentTitle"/></b>
      </html:link>
    </td>
  </tr>
  </logic:present>
</table>


<table class="dataTable" border="0" cellspacing="1" cellpadding="2" summary="reply message list" width="100%">
<tr class="listHeader">
<th id="replies" colspan="3" align="left">
  <bean:message key="cs.message.replies"/>:
</th>
</tr>
<logic:equal name="isMSOwner" scope="request" value="true">
<logic:iterate id="message" name="discussionMessageDTO" property="messages" indexId="index">

<%
Long depthLevelL = (Long) ((DynaBean) message).get("depthLevel");
long i = depthLevelL.longValue() * 12;
%>

 <tr class=<%= index.intValue() % 2 == 0 ? "\"listEven\"" : "\"listOdd\""%>>
   <td width="54%"><html:img page="/cs/images/buttons/global/gbtn_message.gif" width="22" height="18" altKey="cs.message" border="0" align="absmiddle"/><a href="<html:rewrite page="/cs/messageView.do?displayMsg=true" name="message" property="urlParams"/>" style="margin-left: <%=i%>px"><b><bean:write name="message" property="title" /></b></a></td>
<td width="34%"><bean:write name="message" property="lastModTime" formatKey="format.datetime.full"/></td>
    <td nowrap align="left" width="21%">
    <logic:equal name="message" property="status" value="1"> 
     <html:link page="/cs/messageStatusChange.do" name="message" property="urlParams"><html:img page="/cs/images/action/icon_deactivate.gif" styleClass="actionIcon" altKey="cs.action.deactivate" border="0"/></html:link>
    </logic:equal>
    <logic:equal name="message" property="status" value="0"> 
    <html:link page="/cs/messageStatusChange.do" name="message" property="urlParams"><html:img page="/cs/images/action/icon_activate.gif" styleClass="actionIcon" altKey="cs.action.activate" border="0"/></html:link>
    </logic:equal>
      <html:link page="/cs/messageDelete.do" name="message" property="urlParams" onclick="return confirmDeleteMessage()"><html:img page="/cs/images/action/icon_delete.gif" styleClass="actionIcon" altKey="cs.action.delete" border="0"/></html:link> 
    </td>
  </tr>
</logic:iterate>
</logic:equal>

<logic:equal name="isMSOwner" scope="request" value="false">
<logic:iterate id="message" name="discussionMessageDTO" property="messages"  indexId="index">

<%
Long depthLevelL = (Long) ((DynaBean) message).get("depthLevel");
long j = depthLevelL.longValue() * 12;

%>


  <tr class=<%= index.intValue() % 2 == 0 ? "\"listEven\"" : "\"listOdd\""%>>
   <td><html:img page="/cs/images/buttons/global/gbtn_message.gif" width="22" height="18" altKey="cs.message" border="0" align="absmiddle"/><a href="<html:rewrite page="/cs/messageView.do?displayMsg=true" name="message" property="urlParams"/>" style="margin-left: <%=j%>px"><b><bean:write name="message" property="title" /></b></a></td>
<td colspan="2" nowrap width="34%"><bean:write name="message" property="lastModTime" formatKey="format.datetime.full"/></td>

  </tr>

</logic:iterate>
</logic:equal>
      <logic:equal name="discussionMessageDTO" property="messages.empty" value="true">
        <tr class="listOdd">
          <td align="center" colspan="5">
            <bean:message key="cs.collaboration.noDiscussionMessages"/>
          </td>
        </tr>
      </logic:equal>


</table>

            
<!--Start previous, next, message list, discussion index buttons area here-->

    <div class="globalButtonWrap">
      <logic:present name="discussionMessageDTO" property="previousUrlParams" scope="request">
        <input type="button" name="btn5" class="globalButton" value="<bean:message key="cs.message.previous"/>" onclick="location='<html:rewrite page="/cs/messageView.do?displayMsg=true" name="discussionMessageDTO" property="previousUrlParams" scope="request"/>';"/>
      </logic:present>     
      <logic:present name="discussionMessageDTO" property="nextUrlParams" scope="request">
        <input type="button" name="btn6" class="globalButton" value="<bean:message key="cs.message.next"/>" onclick="location='<html:rewrite page="/cs/messageView.do?displayMsg=true" name="discussionMessageDTO" property="nextUrlParams" scope="request"/>';"/>
      </logic:present>  
      <input type="button" name="btn7" class="globalButton" value="<bean:message key="cs.message.list"/>" onclick="location='<html:rewrite page="/cs/discussionView.do?displayMsg=true" name="micrositeNaviInfoView" property="urlParams"/>'">
      <input type="button" name="btn8" class="globalButton" value="<bean:message key="cs.discussions.index"/>" onclick="location='<html:rewrite page="/cs/discussionList.do" name="micrositeNaviInfoView" property="urlParams"/>'">
    </div>
 
<!--end main content area here-->

  </div> <!-- end 1st blockwrap  --> 


<!--start create a reply to area here-->
<logic:notEqual name="isMSReadOnly" scope="request" value="true">
<a name="#reply"></a>

<%-- <form name="postForm" action="/cgi-bin/cp_upload.exe" 
      method="post" enctype="multipart/form-data"> --%>



<html:form action="/cs/messageSave.do">

<bvhtml:hiddenList name="micrositeNaviInfoView" property="urlParams" scope="request"/>

<input type="hidden" name="returnId" value="<bean:write name="discussionMessageDTO" property="id"/>">
<html:hidden name="csMessageListEditForm" property="sequenceKey"/>
<input type="hidden" name="parentContentType" value="25"/> <!-- message cnt type -->
 
<!--start reply message table here-->
<!--start title bar here-->
<div class="pageSubtitle">
  <span class="left">
    <bean:message key="cs.message.create.reply.to"/> "<bean:write name="discussionMessageDTO" property="title"/>"
  </span>
</div>  

<div class="blockWrap">
      
<table class="labelForm" width="100%" border="0" cellspacing="0" 
     cellpadding="0" summary="Replay message table">
     
  <tr>
    <td width=20% class="label"><bean:message key="cs.message.email"/>*:</td>
    <td width=80% class="labelField">
      <html:text size="28" maxlength="80" readonly="true" name="csMessageListEditForm" property="email"/> 
    </td>
  </tr>
  <tr>
    <td width=20% class="label"><bean:message key="cs.message.subject"/>*:</td>
    <td width=80% class="labelField">
      <html:text size="31" maxlength="80" name="csMessageListEditForm" property="title"/> 
    </td>
  </tr>
  <tr>
    <td width=20% class="label"><bean:message key="cs.message.content"/>:</td>
    <td width=80% class="labelField">
      <textarea cols="30" rows="5" name="body" wrap="virtual"><bean:write name="csMessageListEditForm" property="body"/></textarea>
    </td>
  </tr>
  
  </table>
<!-- start of attachments secion -->
<% // Need to define the attachment form bean for the included JSP %>
   <!-- Start Display attachment. -->
    <script language="JavaScript">
      var nextPage = '<html:rewrite page="/cs/messageReplyAttachmentAdd.do"/>';
      var attachmentDeleteAction = '<html:rewrite page="/cs/messageReplyAttachmentDelete.do" />';

      <logic:equal name="csMessageListEditForm" property="numFiles" value="0">
        var nextActionAfterCancel= '/cs/messageView.do';
      </logic:equal>
      <logic:notEqual name="csMessageListEditForm" property="numFiles" value="0">
        var nextActionAfterCancel= '/cs/messageCancel.do';
      </logic:notEqual>
  
      var nextActionAfterReset = '/cs/messageView.do';
      
    </script>
    
    <bean:define id="formBeanUsed" name="csMessageListEditForm" toScope="request" />
    <%@ include file="/cs/microsite/attachment/attachmentEdit.jsp" %>
    <!-- end of attachments secion -->

 
<!--end main content area here-->

<!--start cancel, reset, save bar area here-->
 <div class="pageButtonWrap" align="right">
   <html:reset styleClass="pageButton" property="resetBtn" titleKey="cs.message.clear"
        onclick='return resetAttachment(this.form)'>
     <bean:message key="cs.message.clear"/>
   </html:reset>   
   <html:button styleClass="pageButton" property="postBtn" 
       titleKey="cs.message.post.your.reply" onclick="onClickPost()">
     <bean:message key="cs.message.post.your.reply" />
   </html:button>
           
 </div>

    <!--end cancel, reset, save bar area here-->
</html:form>
</logic:notEqual>

</div> <!-- end of blockWrap -->

</td>
</tr>
</table>

